/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.postprocessor;


/**
 * ThreadGroup singleton for managing threads spawned after a struts action has completed execution.
 * 
 * @see org.jaxson.struts.postprocessor.PostRequestProcessorThread
 * @see org.jaxson.struts.postprocessor.PostRequestProcessor
 * 
 * @author Joe Maisel
 */
public class PostProcessorThreadGroup extends ThreadGroup
{
	private static PostProcessorThreadGroup instance;

	private PostProcessorThreadGroup ()
	{
		super( PostProcessorThreadGroup.class.getName() );
	}

	public static final PostProcessorThreadGroup getInstance()
	{
		if( instance == null )
			instance = new PostProcessorThreadGroup();

		return instance;
	}

	public static PostRequestProcessorThread get( String sessionid, String prpName )
	{
		PostRequestProcessorThread[] threads = new PostRequestProcessorThread[getInstance().activeCount()];
		getInstance().enumerate( threads );

		for( PostRequestProcessorThread thread : threads )
		{
			if( thread.getName().equals( sessionid + prpName ) )
				return thread;
		}

		return null;
	}
}
